package com.chuanyang.driverh.mainmy.fragment;


import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.view.View;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.chuanyang.driverh.R;
import com.chuanyang.driverh.base.BaseFragment;
import com.chuanyang.driverh.utils.widget.MyViewPager;

import java.util.ArrayList;

public class HistoryOrderWaybillFragment extends BaseFragment implements RadioGroup.OnCheckedChangeListener {
    private MyViewPager vp_orderbill;
    private ArrayList list;
    private OrderHisFragment orderFragment;
    private WaybillHisFragment waybillFragment;
    private FragmentPagerAdapter adapter;

    RadioGroup rg_common;
    RadioButton rb_left;
    RadioButton rb_right;


    @Override
    protected int getLayoutResId() {
        return R.layout.common_frag_tab_two;
    }
    @Override
    protected void initView(View view) {
        rg_common=(RadioGroup)rootView.findViewById(R.id.rg_common);
        rb_left=(RadioButton)rootView.findViewById(R.id.rb_left);
        rb_right=(RadioButton)rootView.findViewById(R.id.rb_right);
        rb_left.setText("历史订单");
        rb_right.setText("历史运单");
    }

    @Override
    protected void initData() {
        vp_orderbill = (MyViewPager) rootView.findViewById(R.id.vp_common);
        list = new ArrayList();
        list = new ArrayList();
        orderFragment = new OrderHisFragment();
        waybillFragment = new WaybillHisFragment();
        list.add(orderFragment);
        list.add(waybillFragment);
        adapter = new FragmentPagerAdapter(getChildFragmentManager());
        vp_orderbill.setAdapter(adapter);
    }

    @Override
    protected void initListener() {
        rg_common.setOnCheckedChangeListener(this);
    }
    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        switch (checkedId){
            case R.id.rb_left:
                vp_orderbill.setCurrentItem(0);
                orderFragment.onRefresh();
                break;
            case R.id.rb_right:
                vp_orderbill.setCurrentItem(1);
                waybillFragment.onRefresh();
                break;
        }
    }


    class FragmentPagerAdapter extends android.support.v4.app.FragmentPagerAdapter {
        public FragmentPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public int getCount() {
            return list.size();
        }

        @Override
        public Fragment getItem(int position) {
            return (Fragment) list.get(position);
        }

        @Override
        public int getItemPosition(Object object) {
            return super.getItemPosition(object);
        }
    }
}
